package com.ibeeking.gmc.global.g.rest.controller.v1;

import com.ibeeking.gmc.global.g.rest.service.ITenantDataAuthService;
import com.ibeeking.found.common.annotation.LoginUser;
import com.ibeeking.found.common.entity.CurrentUser;
import com.ibeeking.gmc.global.api.common.param.ApprovalDataAuthParam;
import com.ibeeking.gmc.global.api.common.param.TenantDataAuthParam;
import com.ibeeking.gmc.global.service.common.vo.TenantDataAuthVO;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName TenantDataAuthController控制器
 * @Description 租户间数据授权申请
 * @Author ibeeking
 * @Date 2020-12-02 15:29
 **/
@RestController
@RequestMapping("/b/dataAuth/v1")
public class TenantDataAuthController {

    @Resource
    private ITenantDataAuthService tenantDataAuthServiceImpl;

    @Log(logType = OperateLogTypeEnum.SAVE, describe = "申请租户数据授权")
    @PostMapping(value = "/applyAuth")
    public Boolean applyAuth(@LoginUser CurrentUser currentUser,@RequestBody TenantDataAuthParam param) {
        return tenantDataAuthServiceImpl.applyAuth(currentUser,param);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "审批租户数据授权")
    @PostMapping(value = "/approvalAuth")
    public Boolean approvalAuth(@LoginUser CurrentUser currentUser,@RequestBody ApprovalDataAuthParam param) {
        return tenantDataAuthServiceImpl.approvalAuth(currentUser, param);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "终止租户数据授权")
    @PostMapping(value = "/stopAuth")
    public Boolean stopAuth(@LoginUser CurrentUser currentUser,@RequestBody ApprovalDataAuthParam param) {
        return tenantDataAuthServiceImpl.stopAuth(currentUser, param);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查询当前租户数据授权列表")
    @PostMapping(value = "/listDataAuth")
    public List<TenantDataAuthVO> listDataAuth(@LoginUser CurrentUser currentUser) {
        return tenantDataAuthServiceImpl.listDataAuth(currentUser);
    }
}
